package com.gx.smart.building.ui.swap.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.RadioGroup;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.gx.smart.base.BaseAdapter;
import com.gx.smart.building.R;
import com.gx.smart.building.databinding.ItemSwapDeviceConfirmLayoutBinding;
import com.huishi.gx.ib.grpc.lib.ib.admin.schedule.v1.RecordContent;

import java.util.List;

/**
 * @author: xiaosy
 * 时间: 2022/9/6
 * @Description: 确认事项
 * @Version: 1.0
 **/
public class SwapDeviceConfirmAdapter extends BaseAdapter<RecordContent, SwapDeviceConfirmAdapter.ViewHolder> {
    private List<RecordContent.Builder> eventList;

    public SwapDeviceConfirmAdapter(Context context, List<RecordContent.Builder> eventList) {
        super(context);
        this.eventList = eventList;
    }

    @Override
    protected int onBindLayout() {
        return R.layout.item_swap_device_confirm_layout;
    }

    @Override
    protected ViewHolder onCreateHolder(View view) {
        ItemSwapDeviceConfirmLayoutBinding binding = ItemSwapDeviceConfirmLayoutBinding
                .inflate(LayoutInflater.from(mContext), (ViewGroup) view, false);
        return new ViewHolder(binding);
    }

    @Override
    protected void onBindData(ViewHolder holder, RecordContent item, int position) {
        holder.binding.title.setText(item.getContentName());
        String value = item.getContentValue();
        if (value.equals("1") || value.equals("是")) {
            holder.binding.yes.setChecked(true);
        } else {
            holder.binding.yes.setChecked(false);
        }
        eventList.get(position).setContentValue("2");
        holder.binding.radioGroup.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(RadioGroup group, int checkedId) {
                if (checkedId == R.id.yes) {
                    eventList.get(position).setContentValue("1");
                } else {
                    eventList.get(position).setContentValue("2");
                }
            }
        });
    }

    public static class ViewHolder extends RecyclerView.ViewHolder {
        private ItemSwapDeviceConfirmLayoutBinding binding;

        public ViewHolder(@NonNull ItemSwapDeviceConfirmLayoutBinding binding) {
            super(binding.getRoot());
            this.binding = binding;
        }
    }
}
